package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.domain.inst.repository.SceneInstRepository;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 通用连接类APN类型属性处理器
 */
public class GeneralApnIdentifyAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteOfferInst offerInst = querySceneInstService.getMainOfferInst(data.getSceneInstId());
        if (Objects.nonNull(offerInst)) {
            String offerId = offerInst.getOfferId();
            if (KiteStringUtils.equalsAny(offerId, "50040703", "50040704")) {
                attr.setIsEdit(KeyConsts.IFTRUE_T);
            }
        }
        super.onShow(attr, inst, data);
    }

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteOfferInst offerInst = querySceneInstService.getMainOfferInst(data.getSceneInstId());
        if (Objects.nonNull(offerInst)) {
            String offerId = offerInst.getOfferId();
            String specId = inst.getSpecId();//产品实例id(prod_id)
            //5G纯数据下拉值多一个 110009542(hyscuiot)
            if(!"50040701".equals(offerId)){
                attr.getAttrValues().removeIf(targetAttr -> KiteStringUtils.equalsAny(targetAttr.getAttrValue(), "110009542"));
            }
            //4G纯数据,非4G纯数据的apn标识下拉值都只有scuiot.njm2mapn和scuiot
            if("2000958".equals(specId) && !"50040702".equals(offerId)){
                List<KiteAttrValue> kiteAttrValues = SceneInstRepository.getKiteAttrValues(attr).stream().filter(val -> KiteStringUtils.equalsAny(val.getAttrValue(), "100006956","100006954")).collect(Collectors.toList());
                attr.setAttrValues(kiteAttrValues);
            }
        }
        super.after(attr, inst, data);
    }
}
